package net.kleinhenz.norabase.client;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import net.kleinhenz.norabase.shared.model.Rune;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.util.SC;

public class PoxNoraURL
{
	public static final int RARITY_COMMON = 0;
	public static final int RARITY_UNCOMMON = 1;
	public static final int RARITY_RARE = 2;
	public static final int RARITY_EXOTIC = 3;
	public static final int RARITY_LIMITED = 4;
	public static final int RARITY_LEGENDARY = 5;

	public static Map<String, Integer> sonyMap = new HashMap<String, Integer>();
	
	static {
		RuneServiceAsync runeService = GWT.create(RuneService.class);
		runeService.fetchSonyMap(new AsyncCallback<Map<String, Integer>>() {
					public void onFailure(Throwable error) {
						SC.say("Error while fetching image id map. Please restart/reload application.");
					}
					public void onSuccess(Map<String, Integer> result) {
						sonyMap.putAll(result);
					}
				});
	}
	
	public static final Map<String, Integer> FACTION = Collections.unmodifiableMap(new HashMap<String, Integer>() {
		private static final long serialVersionUID = 1L; { 
			put("Forsaken Wastes", 1);
			put("Savage Tundra", 2);
			put("K'thir Forest", 3);
			put("Ironfist Stronghold", 4);
			put("Forglar Swamp", 5);
			put("Underdepths", 6);
			put("Sundered Lands", 7);
			put("Shattered Peaks", 8);
		}});
	
	public static String card(String type, int id) {
		
		if (Rune.CHAMPION.equals(type))
			return "http://poxnora.station.sony.com/images/runes/lg/" + sonyMap.get("C" + id) + ".jpg";
		else if (Rune.EQUIPMENT.equals(type))
			return "http://poxnora.station.sony.com/images/runes/lg/" + sonyMap.get("E" + id) + ".jpg";
		else if (Rune.SPELL.equals(type))
			return "http://poxnora.station.sony.com/images/runes/lg/" + sonyMap.get("S" + id) + ".jpg";
		else if (Rune.RELIC.equals(type))
			return "http://poxnora.station.sony.com/images/runes/lg/" + sonyMap.get("R" + id) + ".jpg";
		else 
			return null;
	}
	
	public static String rarityBorder(int rarity) {

		String rarityStr = null;
		switch (rarity) {
			case RARITY_COMMON : rarityStr="com"; break;  
			case RARITY_UNCOMMON : rarityStr="uncom"; break;  
			case RARITY_RARE : rarityStr="rare"; break;  
			case RARITY_EXOTIC : rarityStr="exotic"; break;  
			case RARITY_LIMITED : rarityStr="le"; break;  
			case RARITY_LEGENDARY : rarityStr="pe"; break;  
		}

		return "http://poxnora.station.sony.com/_themes/global/frames/lg_frame_rarity_" + rarityStr + ".gif";
	}
	
	public static String border(int faction1, int faction2) {
		if (faction1>0 && faction2>0)
			return "http://poxnora.station.sony.com/_themes/global/frames/large/" + faction1 + "_" + faction2 + ".gif";
		else 
			return "http://poxnora.station.sony.com/_themes/global/frames/large/" + faction1 + ".gif";
	}

	public static String statIcons() {
		return "http://poxnora.station.sony.com/_themes/global/frames/lg_frame_stats.gif";
	}

	public static String back(int faction1, int faction2) {
		if (faction1>0 && faction2>0)
			return "http://poxnora.station.sony.com/_themes/global/frames/" + faction1 + "_" + faction2 + "-back.gif";
		else 
			return "http://poxnora.station.sony.com/_themes/global/frames/" + faction1 + "-back.gif";
	}
	
	public static String back() {
		return "http://poxnora.station.sony.com/_themes/global/frames/back_none.gif";
	}
}
